package com.bigdata.service.mysql.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.bigdata.model.Result;
import com.bigdata.model.SearchModel;
import com.bigdata.mysql.dao.RmrbMapper;
import com.bigdata.mysql.entity.Columns;
import com.bigdata.mysql.entity.Rmrb;
import com.bigdata.mysql.entity.RmrbExample;
import com.bigdata.service.mysql.RmrbService;
import com.bigdata.service.mysql.base.impl.BaseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class RmrbServiceImpl extends BaseService<RmrbMapper, Rmrb, RmrbExample> implements RmrbService {

	@Override
	public Result queryPage(SearchModel searchModel) {
		RmrbExample example = new RmrbExample();
		Page<Rmrb> page = PageHelper.startPage(searchModel.getPageNumber(), searchModel.getPageSize());
		dao.selectByExample(example);
		Result result = new Result();
		result.setTotal(page.getTotal());
		result.setPages((long) page.getPages());
		result.setList(page.getResult());
		return result;
	}

	@Override
	public Result queryColumn(SearchModel searchModel) {
		List<Columns> list = dao.queryColumnname(searchModel);
		for (Columns columns : list) {
			int k = columns.getColumnName().indexOf("_");
			if (k > -1) {
				String s = columns.getColumnName().substring(0, k);
				String w = columns.getColumnName().substring(k, k + 2);
				w = w.replace("_", "");
				w = w.toUpperCase();
				String w2 = columns.getColumnName().substring(k + 2);
				columns.setColumnName(s + w + w2);
			}
		}
		Result result = new Result();
		result.setList(list);
		return result;
	}

	@Override
	public Result queryColumnNo(SearchModel searchModel) {
		List<Columns> list = dao.queryColumnname(searchModel);
		Result result = new Result();
		result.setList(list);
		return result;
	}
}
